/* eslint-disable no-unused-vars */
import { getToken, setToken, removeToken } from '@/utils/auth'
import { tokenPost, Getdashard } from '@/api/user'
import route from '@/router/index'
export default {
  state() {
    return {
      token: getToken(),
      userInfo: {}
    }
  },
  mutations: {
    getTokenMutations(state, payLoad) {
      state.token = payLoad
      setToken(payLoad)
    },
    removeTokenMutations(state) {
      state.token = {}
      removeToken()
    },
    GetdashardList(state, payLoad) {
      state.userInfo = payLoad
      console.log(state.userInfo)
    },
    removeUserinfo(state) {
      state.userInfo = {}
    }
  },
  actions: {
    async ChangeToken({ commit }, payLoad) {
      const res = await tokenPost(payLoad)
      console.log(res)
      commit('getTokenMutations', res.data)
      route.push('/')
    },
    async GetdashardActions({ commit }) {
      const res = await Getdashard()
      console.log(res)
      commit('GetdashardList', res.data)
    },
    async logout({ commit }) {
      commit('removeTokenMutations')
      commit('removeUserinfo')
    }
  },
  getters: {},
  namespaced: true
}
